// Source : https://leetcode.com/problems/add-digits/
// Author : simba
// Date   : 2016-06-21

package main

import (
	"fmt"
)

func addDigits(num int) int {
	for num >= 10 {
		sum := 0

		for num > 0 {
			sum += num % 10
			num = num / 10
		}
		num = sum
	}
	return num
}

//非循环实现
//func addDigits(num int) int {
//	return 1 + (num-1)%9
//}

func main() {
	//固定测试用例
	s1 := 1
	a1 := addDigits(s1)
	fmt.Println("数", s1)
	fmt.Println("输出答案", a1)
	fmt.Println("正确答案 1")

	s2 := 38
	a2 := addDigits(s2)
	fmt.Println("数", s2)
	fmt.Println("输出答案", a2)
	fmt.Println("正确答案 2")
}
